package com.ticket.controller.api;

import com.ticket.service.IUserService;
import com.ticket.utils.Result;
import com.ticket.vo.LoginVO;
import com.ticket.vo.RegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    public Result<Map<String, String>> login(@Validated @RequestBody LoginVO loginVO) {
        String token = userService.login(loginVO);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        return Result.success(map);
    }

    @PostMapping("/register")
    public Result<Void> register(@Validated @RequestBody RegisterVO registerVO) {
        userService.register(registerVO);
        return Result.success();
    }
} 